﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing;

namespace Extellect.Utilities.Drawing.Imaging
{
    /// <summary>
    /// Collection of colours for an Ironbow palette (similar to some infrared cameras).
    /// </summary>
    public static class Ironbow
    {
        private readonly static Color[] colors = new Color[]
        {
            Color.FromArgb(0,0,0),
            Color.FromArgb(0,0,16),
            Color.FromArgb(0,0,33),
            Color.FromArgb(0,0,42),
            Color.FromArgb(0,0,49),
            Color.FromArgb(0,0,56),
            Color.FromArgb(0,0,63),
            Color.FromArgb(0,0,70),
            Color.FromArgb(0,0,77),
            Color.FromArgb(0,0,83),
            Color.FromArgb(1,0,87),
            Color.FromArgb(2,0,91),
            Color.FromArgb(3,0,95),
            Color.FromArgb(4,0,99),
            Color.FromArgb(5,0,103),
            Color.FromArgb(7,0,106),
            Color.FromArgb(9,0,110),
            Color.FromArgb(11,0,115),
            Color.FromArgb(12,0,116),
            Color.FromArgb(13,0,118),
            Color.FromArgb(16,0,120),
            Color.FromArgb(19,0,122),
            Color.FromArgb(22,0,124),
            Color.FromArgb(25,0,127),
            Color.FromArgb(28,0,129),
            Color.FromArgb(31,0,131),
            Color.FromArgb(34,0,133),
            Color.FromArgb(38,0,135),
            Color.FromArgb(42,0,137),
            Color.FromArgb(45,0,138),
            Color.FromArgb(48,0,140),
            Color.FromArgb(52,0,141),
            Color.FromArgb(55,0,143),
            Color.FromArgb(58,0,144),
            Color.FromArgb(61,0,146),
            Color.FromArgb(63,0,147),
            Color.FromArgb(65,0,148),
            Color.FromArgb(68,0,149),
            Color.FromArgb(71,0,149),
            Color.FromArgb(74,0,150),
            Color.FromArgb(76,0,150),
            Color.FromArgb(79,0,151),
            Color.FromArgb(82,0,151),
            Color.FromArgb(85,0,152),
            Color.FromArgb(88,0,152),
            Color.FromArgb(92,0,153),
            Color.FromArgb(94,0,154),
            Color.FromArgb(97,0,155),
            Color.FromArgb(101,0,155),
            Color.FromArgb(104,0,155),
            Color.FromArgb(107,0,155),
            Color.FromArgb(110,0,156),
            Color.FromArgb(112,0,156),
            Color.FromArgb(114,0,156),
            Color.FromArgb(117,0,157),
            Color.FromArgb(121,0,157),
            Color.FromArgb(124,0,157),
            Color.FromArgb(126,0,157),
            Color.FromArgb(129,0,157),
            Color.FromArgb(132,0,157),
            Color.FromArgb(135,0,157),
            Color.FromArgb(137,0,157),
            Color.FromArgb(140,0,156),
            Color.FromArgb(143,0,156),
            Color.FromArgb(146,0,155),
            Color.FromArgb(149,0,155),
            Color.FromArgb(152,0,155),
            Color.FromArgb(154,0,155),
            Color.FromArgb(157,0,155),
            Color.FromArgb(159,0,155),
            Color.FromArgb(161,0,155),
            Color.FromArgb(164,0,154),
            Color.FromArgb(166,0,154),
            Color.FromArgb(168,0,153),
            Color.FromArgb(170,0,153),
            Color.FromArgb(172,0,152),
            Color.FromArgb(174,0,152),
            Color.FromArgb(175,1,151),
            Color.FromArgb(177,1,151),
            Color.FromArgb(178,1,150),
            Color.FromArgb(180,1,149),
            Color.FromArgb(182,2,149),
            Color.FromArgb(183,3,149),
            Color.FromArgb(185,4,148),
            Color.FromArgb(186,4,147),
            Color.FromArgb(188,5,147),
            Color.FromArgb(189,5,146),
            Color.FromArgb(190,5,146),
            Color.FromArgb(191,6,145),
            Color.FromArgb(192,7,144),
            Color.FromArgb(193,9,143),
            Color.FromArgb(194,10,142),
            Color.FromArgb(195,11,141),
            Color.FromArgb(197,12,139),
            Color.FromArgb(198,13,138),
            Color.FromArgb(200,15,136),
            Color.FromArgb(201,17,134),
            Color.FromArgb(202,18,133),
            Color.FromArgb(203,20,131),
            Color.FromArgb(204,21,129),
            Color.FromArgb(206,23,126),
            Color.FromArgb(207,24,123),
            Color.FromArgb(208,26,121),
            Color.FromArgb(208,27,118),
            Color.FromArgb(209,28,116),
            Color.FromArgb(210,30,113),
            Color.FromArgb(211,32,111),
            Color.FromArgb(212,34,108),
            Color.FromArgb(213,36,104),
            Color.FromArgb(214,38,101),
            Color.FromArgb(216,40,98),
            Color.FromArgb(217,42,95),
            Color.FromArgb(218,44,91),
            Color.FromArgb(219,46,87),
            Color.FromArgb(220,47,81),
            Color.FromArgb(221,49,76),
            Color.FromArgb(222,51,70),
            Color.FromArgb(223,53,65),
            Color.FromArgb(223,54,59),
            Color.FromArgb(224,56,54),
            Color.FromArgb(224,57,48),
            Color.FromArgb(225,59,42),
            Color.FromArgb(226,61,37),
            Color.FromArgb(227,63,31),
            Color.FromArgb(228,65,28),
            Color.FromArgb(228,67,25),
            Color.FromArgb(229,69,23),
            Color.FromArgb(230,71,21),
            Color.FromArgb(231,72,19),
            Color.FromArgb(231,74,17),
            Color.FromArgb(232,76,15),
            Color.FromArgb(233,77,13),
            Color.FromArgb(234,78,11),
            Color.FromArgb(234,80,10),
            Color.FromArgb(235,82,9),
            Color.FromArgb(235,84,8),
            Color.FromArgb(236,86,8),
            Color.FromArgb(236,87,7),
            Color.FromArgb(236,89,7),
            Color.FromArgb(237,91,6),
            Color.FromArgb(237,92,5),
            Color.FromArgb(238,94,4),
            Color.FromArgb(238,95,4),
            Color.FromArgb(239,97,3),
            Color.FromArgb(239,99,3),
            Color.FromArgb(240,100,3),
            Color.FromArgb(240,102,3),
            Color.FromArgb(241,103,2),
            Color.FromArgb(241,104,2),
            Color.FromArgb(241,106,1),
            Color.FromArgb(241,107,1),
            Color.FromArgb(242,109,1),
            Color.FromArgb(242,111,1),
            Color.FromArgb(243,113,1),
            Color.FromArgb(243,114,0),
            Color.FromArgb(243,115,0),
            Color.FromArgb(244,117,0),
            Color.FromArgb(244,119,0),
            Color.FromArgb(244,121,0),
            Color.FromArgb(244,124,0),
            Color.FromArgb(245,126,0),
            Color.FromArgb(245,128,0),
            Color.FromArgb(246,129,0),
            Color.FromArgb(246,131,0),
            Color.FromArgb(247,133,0),
            Color.FromArgb(247,134,0),
            Color.FromArgb(248,136,0),
            Color.FromArgb(248,137,0),
            Color.FromArgb(248,139,0),
            Color.FromArgb(248,140,0),
            Color.FromArgb(249,142,0),
            Color.FromArgb(249,143,0),
            Color.FromArgb(249,144,0),
            Color.FromArgb(249,146,0),
            Color.FromArgb(249,148,0),
            Color.FromArgb(250,150,0),
            Color.FromArgb(250,153,0),
            Color.FromArgb(251,155,0),
            Color.FromArgb(251,157,0),
            Color.FromArgb(252,159,0),
            Color.FromArgb(252,161,0),
            Color.FromArgb(253,163,0),
            Color.FromArgb(253,166,0),
            Color.FromArgb(253,168,0),
            Color.FromArgb(253,170,0),
            Color.FromArgb(253,172,0),
            Color.FromArgb(253,174,0),
            Color.FromArgb(254,176,0),
            Color.FromArgb(254,177,0),
            Color.FromArgb(254,178,0),
            Color.FromArgb(254,181,0),
            Color.FromArgb(254,183,0),
            Color.FromArgb(254,185,0),
            Color.FromArgb(254,186,0),
            Color.FromArgb(254,188,0),
            Color.FromArgb(254,190,0),
            Color.FromArgb(254,191,0),
            Color.FromArgb(254,193,0),
            Color.FromArgb(254,195,0),
            Color.FromArgb(254,197,0),
            Color.FromArgb(254,199,0),
            Color.FromArgb(254,200,0),
            Color.FromArgb(254,202,1),
            Color.FromArgb(254,203,1),
            Color.FromArgb(254,205,2),
            Color.FromArgb(254,206,3),
            Color.FromArgb(254,207,4),
            Color.FromArgb(254,209,6),
            Color.FromArgb(254,211,8),
            Color.FromArgb(254,213,10),
            Color.FromArgb(254,215,11),
            Color.FromArgb(254,216,12),
            Color.FromArgb(254,218,14),
            Color.FromArgb(255,219,16),
            Color.FromArgb(255,220,20),
            Color.FromArgb(255,221,24),
            Color.FromArgb(255,222,28),
            Color.FromArgb(255,224,32),
            Color.FromArgb(255,225,36),
            Color.FromArgb(255,227,39),
            Color.FromArgb(255,228,44),
            Color.FromArgb(255,229,50),
            Color.FromArgb(255,230,56),
            Color.FromArgb(255,231,62),
            Color.FromArgb(255,233,67),
            Color.FromArgb(255,234,73),
            Color.FromArgb(255,236,79),
            Color.FromArgb(255,237,85),
            Color.FromArgb(255,238,92),
            Color.FromArgb(255,238,98),
            Color.FromArgb(255,239,105),
            Color.FromArgb(255,240,111),
            Color.FromArgb(255,241,119),
            Color.FromArgb(255,241,127),
            Color.FromArgb(255,242,135),
            Color.FromArgb(255,243,142),
            Color.FromArgb(255,244,149),
            Color.FromArgb(255,244,156),
            Color.FromArgb(255,245,164),
            Color.FromArgb(255,245,171),
            Color.FromArgb(255,246,178),
            Color.FromArgb(255,247,184),
            Color.FromArgb(255,247,190),
            Color.FromArgb(255,248,195),
            Color.FromArgb(255,248,201),
            Color.FromArgb(255,249,206),
            Color.FromArgb(255,250,212),
            Color.FromArgb(255,251,218),
            Color.FromArgb(255,252,224),
            Color.FromArgb(255,253,229),
            Color.FromArgb(255,253,235),
            Color.FromArgb(255,254,240),
            Color.FromArgb(255,254,244),
            Color.FromArgb(255,255,249),
            Color.FromArgb(255,255,252),
            Color.FromArgb(255,255,255),
        };

        /// <summary>
        /// Loads a color palette with these entries.
        /// </summary>
        public static void Load(ColorPalette colorPalette)
        {
            for (int i = 0; i < colors.Length; i++)
            {
                colorPalette.Entries[i] = colors[i];
            }
        }

        /// <summary>
        /// Gets the color at the specified index.
        /// </summary>
        public static Color GetColorAt(byte index)
        {
            return colors[index];
        }
    }
}
